<?php
require_once($_SERVER['DOCUMENT_ROOT'].'/all.conf.php');
require_once(__PHY_WEB.__DIR_ADM.'/admin.inc.php');

$rReq = validate($_REQUEST, 'action:u|look:u|old_pswd:u|new_pswd:u|rep_pswd:u');
$sMsg = '';
$sAction = $rReq['action'];

if ('update' == $rReq['action']) {
	if (!$rReq['new_pswd']) {
		$sMsg .= '密码不能为空';
	}
	elseif ($rReq['new_pswd'] != $rReq['rep_pswd']) {
		$sMsg .= '两次密码不同';
	}
	elseif (md5($rReq['old_pswd']) != $_ME->get('pswd')) {
		$sMsg .= '旧密码错误';
	}
	else {
		$_ME->set('pswd', md5($rReq['new_pswd']));
		if ($_ME->update()) {
			$sMsg .= '修改完成';
		}
		else {
			$sMsg .= '操作失败';
		}
	}
}

$oUser = $_ME;
$oLeader = new aUser($oUser->get('parent_id'), 'user_cname');
$oUser->set('Leader', $oLeader->get('user_cname'));
$oTpl->assign('rUser', $oUser->getData());

$oTpl->assign('sMsg', $sMsg);
$oTpl->assign('sAction', $sAction);
$oTpl->display(dirname(__FILE__).'/'.basename(__FILE__, '.php').'.tpl');
?>
